@extends('admin.base')
@section('title', '编辑商品')
@section('content')
    <div class="layui-card">
        {{--<fieldset class="layui-elem-field">--}}
            {{--<div class="layui-field-box">--}}
            {{--<span class="layui-breadcrumb" lay-separator=">>">--}}
                {{--<a class="layui-btn-sm" href="{{url('admin/shop/index')}}" style="cursor:pointer;" >商品列表</a>;--}}
                {{--<a class="layui-btn-sm" href="" style="cursor:pointer;" >编辑</a>--}}
                {{--<!-- <a><cite>正文</cite></a> -->--}}
            {{--</span>--}}
            {{--</div>--}}
        {{--</fieldset>--}}
        <fieldset class="layui-elem-field">
            <div class="layui-field-box">
                    <span class="layui-breadcrumb">
                      <a href="/admin/home">首页</a>
                      <a href="/admin/shop/index?page=@if($request->page){{$request->page}}@else 1 @endif&keywords={{$request->keywords}}&label={{$request->label}}&type={{$request->type}}&brand={{$request->brand}}&state={{$request->state}}&sell={{$request->sell}}&month={{$request->month}}&title={{$request->title}}&sort={{$request->sort}}">商品列表</a>
                      <a href="">{{$list->name}} - 编辑</a>
                    </span>
            </div>
        </fieldset>

        <div class="layui-card-body">
            <form class="layui-form layui-form-pane" method="post" action="{{url('/admin/shop/update')}}">
                @csrf
                <div class="layui-form-item">
                    <label class="layui-form-label">商品名</label>
                    <div class="layui-input-inline" style="width:30%;">
                        <input type="type" name="name" value="{{$list['name']}}" required lay-verify="required" placeholder='请输入商品名' autocomplete="off" class="layui-input" >
                    </div>
                    <div class="layui-form-mid layui-word-aux"></div>
                </div>
                <!-- <div class="layui-form-item">
                    <label class="layui-form-label">主图</label>
                    <button type="button" class="layui-btn" id="test3"><i class="layui-icon"></i>上传文件</button>
                    <input type="hidden" name="picname" id="picname" value="{{$list['oldname']}}">
                </div> -->
                <div class="layui-form-item">
                    <label class="layui-form-label">原图</label>
                    <img src="{{$list['picname']}}" height="120px">
                </div>
                <input type="hidden" name="id" value="{{$list['id']}}">
                <div class="layui-form-item" style="display:none">
                    <label class="layui-form-label">品牌</label>
                    <div class="layui-input-inline" style="width:30%;">
                        <select id="sub_pid" name="bid" lay-verify="" lay-search >
                            <option value="0">==请选择==</option>
                            @foreach($all_list2 as $fvo)
                                <option value="{{$fvo->bid}}" @if($fvo->is_exit == 1) disabled="disabled" @endif @if($fvo->bid == $list['bid']) selected @endif><?php echo str_repeat("&nbsp;",substr_count($fvo->path,',')*3);?>|--{{$fvo->name}}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="layui-form-mid layui-word-aux"></div>
                </div>

                <div class="layui-form-item">

                    <label class="layui-form-label">规格组合</label>
                    <div class="layui-input-block">
                        <input type="radio" name="is_attr" value="0" title="无" @if($list['is_attr'] == 0) checked @endif>
                        <input type="radio" name="is_attr" value="1" title="有" @if($list['is_attr'] == 1) checked @endif>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">规格类型</label>
                    <div class="layui-input-inline" style="width:30%;">
                        <select id="sub_pid" name="attrtype_id" lay-verify="" lay-search >
                            <option value="">==请选择==</option>
                            @foreach($all_list3 as $fvo)
                                <option value="{{$fvo->id}}" @if($fvo->id == $list['attrtype_id'])selected @endif>|--{{$fvo->tname}}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="layui-form-mid layui-word-aux"></div>
                </div>
                <div class="layui-form-item" style="display:none">
                    <label class="layui-form-label" >成本价</label>
                    <div class="layui-input-inline" style="width:30%;">
                        <input type="type" name="cost_price" value="{{$list['cost_price']}}" required lay-verify="required" placeholder='请输入成本价' autocomplete="off" class="layui-input" >
                    </div>
                    <div class="layui-form-mid layui-word-aux"></div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">销售价</label>
                    <div class="layui-input-inline" style="width:30%;">
                        <input type="type" name="sell_price" value="{{$list['sell_price']}}" required readonly lay-verify="required" placeholder='请输入销售价' autocomplete="off" class="layui-input" >
                    </div>
                    <div class="layui-form-mid layui-word-aux"></div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">销量</label>
                    <div class="layui-input-inline" style="width:30%;">
                        <input type="type" name="sale_num" value="{{$list['sale_num']}}" required lay-verify="required" placeholder='请输入销量' autocomplete="off" class="layui-input" >
                    </div>
                    <div class="layui-form-mid layui-word-aux"></div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-inline" style="width:30%;">
                        <input type="type" name="sort" value="{{$list['sort']}}" required lay-verify="required" placeholder='请输入排序' autocomplete="off" class="layui-input" >
                    </div>
                    <div class="layui-form-mid layui-word-aux">数字越大,显示越靠前</div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">内容:</label>
                    <div class="layui-input-block">
                        <textarea id="demo" style="display: none;" name="content">{{$list['content']}}</textarea>
                    </div>
                </div>

                <div class="layui-form-item">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </form>
            <input type="hidden" name="page" value="{{$request->page}}">
            <input type="hidden" name="keywords" value="{{$request->keywords}}">
            <input type="hidden" name="label" value="{{$request->label}}">
            <input type="hidden" name="type" value="{{$request->type}}">
            <input type="hidden" name="brand" value="{{$request->brand}}">
            <input type="hidden" name="state" value="{{$request->state}}">
            <input type="hidden" name="sell" value="{{$request->sell}}">
            <input type="hidden" name="month" value="{{$request->month}}">
            <input type="hidden" name="title" value="{{$request->title}}">
            <input type="hidden" name="sort_cy" value="{{$request->sort}}">
        </div>
    </div>
@endsection
@section('js')
    <script type="text/javascript">

        {{--layui.use('form', function(){--}}
        {{--let form = layui.form;--}}
        {{--form.render();--}}
        {{--let editor = CKEDITOR.replace('content');--}}
        {{--//监听提交--}}
        {{--//添加--}}
        {{--form.on('submit(formDemo)', function(data){--}}
        {{--var aa = editor.getData();--}}
        {{--data.field.content = aa;--}}
        {{--$('#content').text(editor.getData());--}}
        {{--layer.confirm('确认执行此操作？', {icon: 3, title:'提示'}, function(index){--}}
        {{--ajax("{{url('admin/shop/update')}}",data.field, function(data){--}}
        {{--layer.close();--}}
        {{--layer.closeAll();--}}
        {{--layer.msg(data.msg);--}}
        {{--if(data.code == 1){--}}
        {{--location.href = '/admin/shop/index';--}}
        {{--}--}}
        {{--});--}}
        {{--});--}}
        {{--return false;--}}
        {{--});--}}
        {{--});--}}

        layui.use('upload',function(){
            var $ = layui.jquery
                ,upload = layui.upload;
            //指定允许上传的文件类型
            upload.render({
                elem: '#test3'
                ,url: '/admin/shop_up' //改成您自己的上传接口
                ,accept: 'file' //普通文件
                ,done: function(res){
                    layer.msg(res.msg);
                    if(res.code == 1){
                        $("#test3").text('上传成功!');
                        $("#picname").val(res.info);
                    }
                }
            });
        });

        layui.use(['layedit','form'],
            function() {
                var layedit = layui.layedit;
                layedit.set({
                    uploadImage: {
                        url: '/admin/shop_editor',
                        type: 'post'
                    }
                });
                var index = layedit.build('demo'); //建立编辑器
                var form = layui.form;
                var layedit = layui.layedit;

                //监听提交
                form.on('submit(formDemo)', function(data){
                    var aa = layedit.getContent(index);
                    data.field.contents = aa;
                    layer.confirm('确认执行此操作？', {icon: 3, title:'提示'}, function(index){
                        ajax("{{url('admin/shop/update')}}",data.field,function(data){
                            layer.close();
                            layer.closeAll();
                            layer.msg(data.msg);
                            if(data.code == 1){
                                var page = $("input[name=page]").val();
                                var keywords = $("input[name=keywords]").val();
                                var label = $("input[name=label]").val();
                                var type = $("input[name=type]").val();
                                var brand = $("input[name=brand]").val();
                                var state = $("input[name=state]").val();
                                var sell = $("input[name=sell]").val();
                                var month = $("input[name=month]").val();
                                var title = $("input[name=title]").val();
                                var sort = $("input[name=sort_cy]").val();

                                location.href = '/admin/shop/index?page='+page+'&keywords='+keywords+'&label='+label+'&type='+type+'&brand='+brand+'&state='+state+'&sell='+sell+'&month='+month+'&title='+title+'&sort='+sort;
                            }
                        });
                    });
                    return false;
                });
            });



    </script>
@endsection
